<template>
    <div>
<h1>修改页面</h1>
<table class="table"> 
<tbody>
    <tr>
        <td>卡券名称</td>
        <td>
            <input type="text" v-model="data.conName">
        </td>
    </tr>
     <tr>
        <td>卡券类型</td>
        <td>
        <select v-model="data.tyoeId">
       <option value="0">请选择类型</option>
    <option v-for="s in Types" :value="s.tid">{{s.typeNames}}</option>
</select>
        </td>
    </tr>
     <tr>
        <td>适用范围</td>
        <td>
       <select v-model="data.rangid">
    <option value="0">请选择门店</option>
    <option v-for="d in mendian" :value="d.pid">{{d.scopeName}}</option>
</select>
        </td>
    </tr>
     <tr>
        <td>适用日期</td>
        <td>
            <span v-for="d in Timsa">
                <input type="checkbox" v-model="timsas" :value="d">{{d}}
            </span>
        </td>
    </tr>
     <tr>
        <td>有效期</td>
        <td>
               <input type="text" v-model="data.magess">
        </td>
    </tr>
     <tr>
        <td>价格</td>
        <td>
               <input type="text" v-model="data.price">
        </td>
    </tr>
     <tr>
        <td>状态</td>
        <td>
            <select v-model="data.stateid">
       <option value="0" >请选择状态</option>
    <option v-for="a in Statesa" :value="a.sid">{{a.stateNames}}</option>
</select>
        </td>
    </tr>
     <tr>
        <td>图片</td>
        <td>
            <input type="file" @change="ImgUrls">
            <img :src="'https://localhost:7109/'+data.imgUrl" style="width: 60px;height: 60px;">
        </td>
    </tr>
     <tr>
        <td></td>
        <td>
            <input type="button" value="更新" class="btn btn-success" @click="Xgs">
        </td>
    </tr>
     <tr>
        <td></td>
        <td></td>
    </tr>
</tbody>
</table>

    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRoute } from 'vue-router';
import { useRouter } from 'vue-router';
const router=useRoute();
const route=useRouter();
onMounted(()=>{
    Ft();
    mendians();
Typess();
States();
})

const Timsa=ref(["周一","周二","周三","周四","周五","周六","周日"])
const timsas=ref([])
//门店表
const mendian=ref([{
"pid": 0,
    "scopeName": ""
}])
const mendians=()=>{
    axios.get("/api/Stope/GetScope").then(res=>{
        mendian.value=res.data;
    })
}
//类型表
const Types=ref([{
    "tid": 0,
    "typeNames": ""
}])
const Typess=()=>{
    axios.get("/api/Type/GetType").then(res=>{
        Types.value=res.data;
    })
}
//状态表
const Statesa=ref([{
     "sid": 0,
    "stateNames": ""
}])
const States=()=>{
    axios.get("/api/State/GetState").then(res=>{
        Statesa.value=res.data;
    })
}

const data=ref({
     "id": 0,
  "conName": "string",
  "tyoeId": 0,
  "rangid": 0,
  "tims": "string",
  "magess": "string",
  "price": 0,
  "num": 0,
  "stateid": 0,
  "imgUrl": "",
  "isdel": true
})

const Xgs=()=>{
      data.value.tims=timsas.value.toString();
    axios.put("/api/Conpoe/UpdateCou",data.value).then(res=>{
        if(res.data>0)
    {
        alert("修改成功");
        route.push({path:"/"})
    }
    else
    {
        alert("修改失败")
    }
    })
}


const Ft=()=>{
    var mid=router.query.id;
    axios.get("/api/Conpoe/GetClass",{params:{id:mid}}).then(res=>{
        data.value=res.data;
        timsas.value=res.data.tims.split(',');
    })
}



const ImgUrls=(e:any)=>{
    var f=e.target.files[0];
    var fa=new FormData();
    fa.append("file",f);
    debugger
    if(f.size>1024*1024)
{
    alert("图片大小不能大于1MB")
    return;
}
if(f.type!="image/jpeg"&&f.type!="image/png" && f.type!="image/gif")
{
    alert("图片必须是png和jpeg和gif格式")
    return;
}

    axios.post("/api/Lode/UpFile",fa).then(res=>{
        data.value.imgUrl=res.data;
        
    })
}


</script>

<style scoped>

</style>